package features;

import java.time.LocalDate;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import com.xlongwei.accounts.service.AccountService;

public class SimpleTest {

    @Test
    public void creditcycle() {
        LocalDate[] creditcycle = null;
        creditcycle = AccountService.creditcycle(1, LocalDate.parse("2025-02-01"));
        Assertions.assertArrayEquals(new LocalDate[] { LocalDate.parse("2024-12-01"), LocalDate.parse("2025-01-01") },
                creditcycle);
        creditcycle = AccountService.creditcycle(1, LocalDate.parse("2025-02-02"));
        Assertions.assertArrayEquals(new LocalDate[] { LocalDate.parse("2025-01-01"), LocalDate.parse("2025-02-01") },
                creditcycle);
        creditcycle = AccountService.creditcycle(2, LocalDate.parse("2025-02-01"));
        Assertions.assertArrayEquals(new LocalDate[] { LocalDate.parse("2024-12-02"), LocalDate.parse("2025-01-02") },
                creditcycle);
        creditcycle = AccountService.creditcycle(2, LocalDate.parse("2025-02-02"));
        Assertions.assertArrayEquals(new LocalDate[] { LocalDate.parse("2024-12-02"), LocalDate.parse("2025-01-02") },
                creditcycle);
        creditcycle = AccountService.creditcycle(2, LocalDate.parse("2025-02-03"));
        Assertions.assertArrayEquals(new LocalDate[] { LocalDate.parse("2025-01-02"), LocalDate.parse("2025-02-02") },
                creditcycle);
        creditcycle = AccountService.creditcycle(28, LocalDate.parse("2025-02-28"));
        Assertions.assertArrayEquals(new LocalDate[] { LocalDate.parse("2024-12-28"), LocalDate.parse("2025-01-28") },
                creditcycle);
        creditcycle = AccountService.creditcycle(28, LocalDate.parse("2025-03-01"));
        Assertions.assertArrayEquals(new LocalDate[] { LocalDate.parse("2025-01-28"), LocalDate.parse("2025-02-28") },
                creditcycle);
        creditcycle = AccountService.creditcycle(30, LocalDate.parse("2025-03-30"));
        Assertions.assertArrayEquals(new LocalDate[] { LocalDate.parse("2025-01-30"), LocalDate.parse("2025-02-28") },
                creditcycle);
        creditcycle = AccountService.creditcycle(30, LocalDate.parse("2025-03-31"));
        Assertions.assertArrayEquals(new LocalDate[] { LocalDate.parse("2025-02-28"), LocalDate.parse("2025-03-30") },
                creditcycle);
        creditcycle = AccountService.creditcycle(31, LocalDate.parse("2025-05-01"));
        Assertions.assertArrayEquals(new LocalDate[] { LocalDate.parse("2025-03-31"), LocalDate.parse("2025-04-30") },
                creditcycle);
        creditcycle = AccountService.creditcycle(31, LocalDate.parse("2025-03-31"));
        Assertions.assertArrayEquals(new LocalDate[] { LocalDate.parse("2025-01-31"), LocalDate.parse("2025-02-28") },
                creditcycle);
    }

    @Test
    public void billRepayDay() {
            Assertions.assertArrayEquals(new int[] { 2, 27 }, AccountService.billRepayDay("测试2/27"));
            Assertions.assertArrayEquals(new int[] { 16, 9 }, AccountService.billRepayDay("测试16/9"));
            Assertions.assertArrayEquals(new int[] { 2, 0 }, AccountService.billRepayDay("测试2"));
            Assertions.assertArrayEquals(new int[] { 0, 0 }, AccountService.billRepayDay("测试"));
            Assertions.assertArrayEquals(new int[] { 2, 0 }, AccountService.billRepayDay("测试2/"));
            Assertions.assertArrayEquals(new int[] { 0, 0 }, AccountService.billRepayDay("测试/"));
    }
}
